﻿@{
    ViewData["Title"] = "ArchivesSheepDetailPage";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div style="margin:36px 36px">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-header">
                <span id="eNumber"></span>
                <span id="presence"></span>
                <span id="statusDays"></span>
                <span id="">大羊舍-333</span>
                <span id="electronicEarNumber"></span>
            </div>
        </div>
        <div class="layui-card-body" style="color:grey;">
            <div class="layui-row layui-col-space1" style="margin-bottom:6px">
                <div class="layui-col-md2">
                    品种：
                    <span class="laySpan" id="sheepBreed"></span>
                </div>
                <div class="layui-col-md2">
                    性别：
                    <span class="laySpan" id="sheepGender"></span>
                </div>
                <div class="layui-col-md2">
                    父耳号：
                    <span class="laySpan" id="fEarNumber"></span>
                </div>
                <div class="layui-col-md2">
                    母耳号：
                    <span class="laySpan" id="mEarNumber"></span>
                </div>
                <div class="layui-col-md2">
                    出生日期：
                    <span class="laySpan" id="sheepBir"></span>
                </div>
                <div class="layui-col-md2">
                    出生重：
                    <span class="laySpan" id="birthWeight"></span>
                </div>
            </div>
            <div class="layui-row layui-col-space1" style="margin-bottom:6px">
                <div class="layui-col-md2">
                    出生场地：
                    <span class="laySpan" id="weaningWeigh"></span>
                </div>
                <div class="layui-col-md2">
                    断奶日龄：
                </div>
                <div class="layui-col-md2">
                    断奶重：
                </div>
                <div class="layui-col-md2">
                    日龄：
                </div>
                <div class="layui-col-md2">
                    月龄：
                </div>
                <div class="layui-col-md2">
                    同胎数：
                </div>
            </div>
            <div class="layui-row layui-col-space1" style="margin-bottom:6px">
                <div class="layui-col-md2">
                    生产等级：
                </div>
                <div class="layui-col-md2">
                    基因等级：
                </div>
                <div class="layui-col-md2">
                    销售等级：
                    <span class="laySpan" id="salesGrade"></span>
                </div>
                <div class="layui-col-md2">
                    繁殖方式：
                </div>
                <div class="layui-col-md2">
                    当前胎次：
                </div>
                <div class="layui-col-md2">
                    已产胎次：
                </div>
            </div>
            <div class="layui-row layui-col-space1" style="margin-bottom:6px">
                <div class="layui-col-md2">
                    配种序号：
                </div>
                <div class="layui-col-md2">
                    创建人：
                    <span class="laySpan" id="createBy"></span>
                </div>
                <div class="layui-col-md2">
                    修改人：
                    <span class="laySpan" id="updateBy"></span>
                </div>
                <div class="layui-col-md2">
                    创建时间：
                    <span class="laySpan" id="createDate"></span>
                </div>
                <div class="layui-col-md2">
                    修改时间：
                    <span class="laySpan" id="updateDate"></span>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title" style="text-align:center">
            <li class="layui-this">系谱</li>
            <li>生产记录</li>
            <li>转舍记录</li>
            <li>档案卡</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div style="text-align:center;margin-bottom:20px">
                    <div class="layui-badge layui-bg-green" style="width:60px;height:30px;margin-right:10px">
                        <p id="grandFatherEarNumber" style="margin-top:8px"></p>
                    </div>
                    <div class="layui-badge" style="width:60px;height:30px;margin-right:10px">
                        <p id="grandMotherEarNumber" style="margin-top:8px"></p>
                    </div>
                    <div class="layui-badge layui-bg-green" style="width:60px;height:30px;margin-right:10px">
                        <p id="grandPaFatherEarNumber" style="margin-top:8px"></p>
                    </div>
                    <div class="layui-badge" style="width:60px;height:30px;">
                        <p id="grandPaMotherEarNumber" style="margin-top:8px"></p>
                    </div>
                </div>
                <div style="text-align:center;margin-bottom:20px">
                    <div class="layui-badge layui-bg-green" style="width:60px;height:30px;margin-right:10px">
                        <p id="fatherEarNumber" style="margin-top:8px"></p>
                    </div><div class="layui-badge" style="width:60px;height:30px;">
                        <p id="motherEarNumber" style="margin-top:8px"></p>
                    </div>
                </div>
                <div style="text-align:center">
                    <div class="layui-badge layui-bg-green" style="width:60px;height:30px;">
                        <p id="earNumber" style="margin-top:8px"></p>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <table class="layui-hide" id="produce" lay-filter="produce"></table>
            </div>
            <div class="layui-tab-item">
                <table class="layui-hide" id="transfer" lay-filter="transfer"></table>
            </div>
            <div class="layui-tab-item">
                <table class="layui-table" id="archives" lay-filter="archives">
                    @*   <thead>
                    <tr>
                    <th lay-data="{type:'numbers',fixed:'left',align:'center'}" rowspan="2">序号</th>
                    <th lay-data="{field:'username',align:'center'}" rowspan="2">胎次</th>
                    <th lay-data="{align:'center'}" colspan="6">配种情况</th>
                    <th lay-data="{align:'center'}" colspan="10">产羔情况</th>
                    <th lay-data="{align:'center'}" colspan="3">断奶情况</th>
                    </tr>
                    <tr>
                    <th lay-data="{field:'', width:100,align:'center'}">配种日期</th>
                    <th lay-data="{field:'', width:100,align:'center'}">种公耳号</th>
                    <th lay-data="{field:'', width:100,align:'center'}">种公品种</th>
                    <th lay-data="{field:'', width:100,align:'center'}">种母发情类型</th>
                    <th lay-data="{field:'', width:100,align:'center'}">妊检日期</th>
                    <th lay-data="{field:'', width:100,align:'center'}">妊检结果</th>
                    <th lay-data="{field:'', width:100,align:'center'}">预产日期</th>
                    <th lay-data="{field:'', width:100,align:'center'}">分娩日期</th>
                    <th lay-data="{field:'', width:100,align:'center'}">活羔</th>
                    <th lay-data="{field:'', width:100,align:'center'}">健羔</th>
                    <th lay-data="{field:'', width:100,align:'center'}">窝重</th>
                    <th lay-data="{field:'', width:100,align:'center'}">弱羔</th>
                    <th lay-data="{field:'', width:100,align:'center'}">畸形</th>
                    <th lay-data="{field:'', width:100,align:'center'}">死胎</th>
                    <th lay-data="{field:'', width:100,align:'center'}">木乃伊</th>
                    <th lay-data="{field:'', width:100,align:'center'}">畸胎</th>
                    <th lay-data="{field:'', width:100,align:'center'}">断奶日期</th>
                    <th lay-data="{field:'', width:100,align:'center'}">断奶只数</th>
                    <th lay-data="{field:'', width:100,align:'center'}">断奶窝重</th>
                    </tr>
                    </thead> *@
                </table>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['jquery', 'layer', 'table'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var Id = window.location.search.split("=")[1];
        var table = layui.table;
        var earNumber = "";

        // 就绪函数
        $(function () {
            getArchivesSheepDetailPage();
            getParent();
        })

        // 获取养殖详情
        function getArchivesSheepDetailPage() {
            // 页面加载时自动发送 AJAX 请求
            $.ajax({
                url: 'http://10.31.60.18:8000/ArchivesGetRout/api/Archives/ArchivesReadById?Id=' + Id, // 后台接口地址
                type: 'get',
                success: function (data) {
                    getListData(data.earNnumber);
                    getArchivesData(data.earNnumber);
                    $('#eNumber').text(data.earNnumber);
                    $('#presence').text(data.presence);
                    $('#electronicEarNumber').text(data.electronicEarNumber);
                    $('#sheepBreed').text(data.sheepBreed);
                    $('#fEarNumber').text(data.fatherEarNumber);
                    $('#mEarNumber').text(data.motherEarNumber);
                    $('#sheepBir').text(data.sheepBir.substring(0, 10));
                    $('#sheepGender').text(data.sheepGender == true ? "公" : "母");
                    $('#birthWeight').text(data.birthWeight + "公斤");
                    $('#salesGrade').text(data.salesGrade);
                    $('#createBy').text(data.createBy);
                    $('#createDate').text(data.createDate != null ? data.createDate.substring(0, 10) : data.createDate);
                    $('#updateBy').text(data.updateBy);
                    $('#updateDate').text(data.updateDate != null ? data.updateDate.substring(0, 10) : data.updateDate);
                },
                error: function (xhr, status, error) {
                    layer.msg('请求失败', { icon: 2 });
                }
            });
        }

        // 获取父系信息
        function getParent() {
            $.ajax({
                url: 'http://10.31.60.18:8000/ArchivesGetRout/api/Archives/ArchivesSheepGenealogyRead?Id=' + Id, // 后台接口地址
                type: 'get',
                success: function (data) {
                    // 在这里处理后台返回的数据
                    $('#earNumber').text(data.earNumber);
                    $('#fatherEarNumber').text(data.fatherEarNumber);
                    $('#motherEarNumber').text(data.motherEarNumber);
                    $('#grandFatherEarNumber').text(data.grandFatherEarNumber);
                    $('#grandMotherEarNumber').text(data.grandMotherEarNumber);
                    $('#grandPaFatherEarNumber').text(data.grandPaFatherEarNumber);
                    $('#grandPaMotherEarNumber').text(data.grandPaMotherEarNumber);

                    // 这里只是简单的打印数据到控制台，你可以根据实际情况进行其他操作
                },
                error: function (xhr, status, error) {
                    layer.msg('请求失败', { icon: 2 });
                }
            });
        }

        // 生产记录表格渲染
        table.render({
            elem: '#produce',
            url: '', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                { field: 'username', title: '日期', align: 'center' },
                { field: 'sex', title: '繁殖状态', align: 'center' },
                { field: 'sex', title: '内容', width: 800, align: 'center' },
                { field: 'sex', title: '流水号', align: 'center' },
            ]],
            data: [],
            error: function (res, msg) {
                console.log(res, msg)
            }
        });

        // 转舍记录表格渲染
        function getListData(earNumber) {
            //ajax后台交互
            $.ajax({
                url: `http://10.31.60.18:8000/ProduceGetRout/api/SheepRescissionRead/GetSheepResList`,
                type: 'get',
                data: {
                    visualEarSignal: earNumber
                },
                contentType: 'application/json',
                dataType: 'json',
                success: function (res) {
                    console.log(res);
                    table.render({
                        elem: '#transfer',
                        url: ``, // 此处为静态模拟数据，实际使用时需换成真实接口
                        cols: [[
                            {
                                field: 'surrenderDate', title: '日期', align: 'center',
                                templet: function (data) { return data.surrenderDate.substring(0, 10) }
                            },
                            { field: 'roundType', title: '繁殖状态', align: 'center' },
                            {
                                field: '', title: '内容', align: 'center',
                                templet: function (data) {
                                    return `转出栋舍"${data.turnBuilding}"，栏位"${data.rolloutField}"，转入栋舍"${data.transferBuilding}"，栏位"${data.driveField}"`
                                }
                            }
                        ]],
                        data: res,
                        error: function (res, msg) {
                            console.log(res, msg)
                        }
                    });
                }
            });
        }

        // 档案卡表格渲染
        function getArchivesData(earNumber) {
            alert(earNumber);
            //ajax后台交互
            $.ajax({
                url: `http://10.31.60.18:8000/ProduceGetRout/api/GermlineHistoryRecordsRead/GetGermlineHistoryList`,
                type: 'get',
                data: {
                    motherEarHorn: earNumber
                },
                contentType: 'application/json',
                dataType: 'json',
                success: function (res) {
                    console.log(res);
                    table.render({
                        elem: '#archives',
                        url: ``, // 此处为静态模拟数据，实际使用时需换成真实接口
                        cols: [[
                            { type: 'numbers', align: 'center', rowspan: 2 },
                            { field: '', title: '胎次', align: 'center', rowspan: 2 },
                            { title: '配种情况', align: 'center', colspan: 6 },
                            { title: '产羔情况', align: 'center', colspan: 10 },
                            { title: '断奶情况', align: 'center', colspan: 3 },
                        ], [
                            {
                                field: 'dateOfBreeding', title: '配种日期', width: 120, align: 'center',
                                templet: function (data) { return data.dateOfBreeding.substring(0, 10) }
                            },
                            { field: 'breedEarHorn', title: '种公耳号', width: 120, align: 'center' },
                            { field: 'sireBreed', title: '种公品种', width: 120, align: 'center' },
                            { field: 'damType', title: '种母发情类型', width: 120, align: 'center' },
                            {
                                field: 'pregnancyTestDate', title: '妊检日期', width: 120, align: 'center',
                                templet: function (data) { return data.pregnancyTestDate.substring(0, 10) }
                            },
                            { field: 'pregnancyTestResult', title: '妊检结果', width: 120, align: 'center' },
                            {
                                field: 'pregnancyTestDate', title: '预产日期', width: 120, align: 'center',
                                templet: function (data) { return data.pregnancyTestDate.substring(0, 10) }
                            },
                            {
                                field: 'pregnancyTestDate', title: '分娩日期', width: 120, align: 'center',
                                templet: function (data) { return data.pregnancyTestDate.substring(0, 10) }
                            },
                            { field: 'pregnancyCheckResult', title: '活羔', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '健羔', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '窝重', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '弱羔', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '畸形', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '死胎', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '木乃伊', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '畸胎', width: 120, align: 'center' },
                            {
                                field: 'pregnancyTestDate', title: '断奶日期', width: 120, align: 'center',
                                templet: function (data) { return data.pregnancyTestDate.substring(0, 10) }
                            },
                            { field: 'pregnancyCheckResult', title: '断奶只数', width: 120, align: 'center' },
                            { field: 'pregnancyCheckResult', title: '断奶窝重', width: 120, align: 'center' },
                        ]],
                        data: res,
                        error: function (res, msg) {
                            console.log(res, msg)
                        }
                    });
                }
            });
        }
    })
</script>

<style>
    .laySpan {
        color: black;
    }
</style>